// subpages0//memberConsumDetail/memberConsumDetail.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showLoading: true,
    noMoretip: false,
    page: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    console.log('下级mid',e.mid)
    if(e&&e.mid){
      this.setData({
        mid:e.mid
      })
    }
    this.requestOrderList();
  },
  //请求下级会员列表
  requestOrderList: function () {
    var that = this;
    var data = {};
    var page = that.data.page;
    var mid = that.data.mid;
    data.map = 'applet_three_subordinate_back';
    data.page = page;
    data.mid = mid;
    wx.request({
      url: app.globalData.requestUrl,
      data: data,
      success: function (res) {
        console.log(page);
        console.log(res.data);
        if (res.data.ec == 200) {
          var allArr = [];
          var initArr = that.data.orderList ? that.data.orderList : [];
          var curArr = res.data.data;
          var lastPageLength = curArr.length;
          if (page > 0) {
            allArr = initArr.concat(curArr);
          } else {
            allArr = res.data.data;
          }
          that.setData({
            orderList: allArr
          })
          if (lastPageLength < 10) {
            that.setData({
              noMoretip: true,
              showLoading: false
            });
          }
          console.log(that.data.orderList);
        } else {
          if (page <= 0) {
            that.setData({
              orderList: [],
              noMoretip: false,
              showLoading: false
            })
          } else {
            that.setData({
              noMoretip: true,
              showLoading: false
            });
          }
        }
      },
      complete: function () {
        wx.hideToast();
        wx.stopPullDownRefresh();
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var that = this;
    that.setData({
      page: 0,
      noMoretip: false,
      showLoading: true
    });
    that.requestOrderList();
    console.log("下拉刷新");
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    console.log("到达页面底部")
    var isMore = that.data.noMoretip;
    
    if (isMore) {
      var page = that.data.page;
      page++;
      that.setData({
        page: page
      });
      console.log("已完成或正在加载");
    } else {
      that.requestOrderList();
    }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})